<template>
  <div class="home-container">
    <!-- 1.navbar顶部栏： -->
    <van-nav-bar class="page-nav-bar" fixed>
      <template #left>
        <div class="logo"></div>
      </template>
      <template #right>
        <van-button
          class="search-btn"
          icon="search"
          type="info"
          size="small"
          round
          @click="$router.push({ path: '/MyUser' })"
        >
          搜索
        </van-button>
      </template>
    </van-nav-bar>
    <!-- 2.tab栏 -->
    <!-- 频道列表 -->
<!--
animated 滑动的动画
border 底边框线
swipeable 开启左右手势滑动
-->
<van-tabs class="channel-tabs" v-model="active" swipeable animated border>
<van-tab  v-for="item in channels" :key="item.id" :title="item.name">{{ item.name }}</van-tab>
<!-- 右侧自定义内容 -->
<!-- 占位元素 -->
<div slot="nav-right" class="placeholder"></div>
<!-- 右侧按钮 -->
<div slot="nav-right" class="hamburger-btn">
  <i class="toutiao toutiao-gengduo"></i>
</div>
</van-tabs>
  </div>
</template>
<script>
import { getUserChannels } from '@/api/user'
export default {
  name: 'MyHome-page',
  data () {
    return {
      // 频道列表
      channels: [],
      active: 0
    }
  },
  created () {
    this.loadChannels()
  },
  // 方法：
  methods: {
    // 获取用户频道列表
    async loadChannels () {
      try {
        const res = await getUserChannels()
        console.log(res, 'getUserChannels')
        this.channels = res.data.channels
      } catch (error) {
        this.$toast('获取频道列表数据失败')
      }
    }
  }
}
</script>

<style lang="less">
 /deep/ .channel-tabs {
    .van-tabs__wrap {
      position: fixed;
      top: 92px;
      z-index: 1;
      left: 0;
      right: 0;
      height: 82px;
    }

    .van-tab {
      border-right: 1px solid #edeff3;
      min-width: 200px;
      font-size: 30px;
      color: #777777;
    }

    .van-tab--active {
      color: #333333;
    }

    .van-tabs__nav {
      padding-bottom: 0;
    }

    .van-tabs__line {
      bottom: 8px;
      width: 31px !important;
      height: 6px;
      background-color: #3296fa;
    }

    .placeholder {
      flex-shrink: 0;
      width: 66px;
      height: 82px;
    }

    .hamburger-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      background-color: rgba(255, 255, 255, 0.902);
      i.toutiao {
        font-size: 33px;
      }
      &:before {
        content: "";
        position: absolute;
        left: 0;
        width: 1px;
        height: 58px;
        background-image: url(@/assets/logo.png);
        background-size: contain;
      }
    }
  }
</style>
